package com.jike.mahjong.task;

import com.jike.mahjong.common.util.PropertyUtil;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;

/**
 * Created by star on 2016/12/28.
 */

@Component
public class TaskUtil {


    private static final List<Timer> timerList=new ArrayList<Timer>();

    /*private final static  Timer timer = new Timer();
    private final  static MsgTask timeTask=new MsgTask("");*/
    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    public  static int count=0;
   /* @PostConstruct
    public static void sendMsg(){
        String content=PropertyUtil.getPropertyValue("content");
        if(content!=null){
            timeTask.setContent(PropertyUtil.getPropertyValue("content"));
        }
        String freStr=PropertyUtil.getPropertyValue("frequency");
        if(freStr!=null&&!"".equals(freStr)){
            int frequency=Integer.valueOf(freStr);
            timer.scheduleAtFixedRate(timeTask, 0, frequency*1000);
            count++;
        }

    }*/

    /*@PostConstruct*/
    public static void sendMsg() {
        Timer timer = new Timer();
        MsgTask timeTask=new MsgTask("");
        String content = PropertyUtil.getPropertyValue("content");
        if (content != null) {
            timeTask.setContent(PropertyUtil.getPropertyValue("content"));
        }
        String freStr = PropertyUtil.getPropertyValue("frequency");
        if (freStr != null && !"".equals(freStr)) {
            int frequency = Integer.valueOf(freStr);
            timer.scheduleAtFixedRate(timeTask, 0, frequency * 1000);
            count++;
            timerList.add(timer);
        }
    }


   /* public static Timer getTimer() {
        return timer;
    }

    public static MsgTask getTimeTask() {
        return timeTask;
    }*/

    public static List<Timer> getTimerList() {
        return timerList;
    }
}
